package com.dingding.order.core.myorder.biz.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.AbstractResponse;
import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.order.core.myorder.biz.IGetHistoryOrderService;
import com.dingding.order.core.myorder.dao.IGetMyOrderDao;
import com.dingding.order.dto.myorder.HistoryOrder;
import com.dingding.order.dto.myorder.ReqHistoryOrderDTO;
import com.dingding.order.dto.myorder.ResHistoryOrderDTO;
import com.dingding.order.dto.myorder.UserTakeInformation;

/**
 * 
 * @ClassName: IGetHistoryOrderService 
 * @Description: 获取历史订单Service
 * @author YHQ
 * @date 2016年9月22日 上午11:57:04
 * @since V2.5.0
 * 
 */
@Component("getHistoryOrderService")
public class GetHistoryOrderServiceImpl extends AbstractResponse<ResHistoryOrderDTO, ReqHistoryOrderDTO> implements IGetHistoryOrderService {

	@Resource(name = "getMyOrderDao")
	IGetMyOrderDao getMyOrderDao;
	
	/**
	 * 
	 * @Title: getHistoryOrders 
	 * @Description: 获取历史订单
	 * @param requestData 客户端请求参数
	 * @author YHQ 
	 * @since V2.5.0
	 * @return String    返回类型
	 * 
	 */
	public String getHistoryOrders(String requestData){
		
		// 封装响应bean
		ResponseEntity<HistoryOrder> response = new ResponseEntity<HistoryOrder>();
		
		// 将请求转换成bean
		ReqHistoryOrderDTO reqHistoryOrderDTO = super.parseRequestJson(requestData);
		
		// 1.验证参数
		if (!validateParam(response, reqHistoryOrderDTO)) {
			return super.responseBeanToJson(response);
		}
		
		// 2.获得我的订单
		List<ResHistoryOrderDTO> orderLists = getMyOrderDao.getHistoryOrder(reqHistoryOrderDTO);
		// 3.获得用户总搭乘和总接乘次数
		UserTakeInformation userTakeInformation = getMyOrderDao.getUserTakeImformation(reqHistoryOrderDTO.getUserId());
		HistoryOrder historyOrders = new HistoryOrder();
		historyOrders.setOrderList(orderLists);
		historyOrders.setPickUpMeters(userTakeInformation.getPickUpMeters());
		historyOrders.setRideMeters(userTakeInformation.getRideMeters());
		
		response.setResponseBody(historyOrders);
		response.setCode(HttpStatus.SC_OK);
		
		return super.responseBeanToJson(response);
	}
	
}
